package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/zrpc"
	"hzjt-oam/admin/internal/config"
	"hzjt-oam/rpc/sys/usersrv"
)

type ServiceContext struct {
	Config  config.Config
	UserSrv usersrv.Usersrv
	Redis   *redis.Redis
}

func NewServiceContext(c config.Config) *ServiceContext {
	newRedis := redis.New(c.Redis.Host, redisConfig(c))
	return &ServiceContext{
		Config:  c,
		UserSrv: usersrv.NewUsersrv(zrpc.MustNewClient(c.SysRpc)),
		Redis:   newRedis,
	}
}

func redisConfig(c config.Config) redis.Option {
	return func(r *redis.Redis) {
		r.Type = redis.NodeType
		r.Pass = c.Redis.Pass
	}
}
